package com.blue.tooth.lock.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.blue.tooth.lock.R;


public class CustomAlertDialog {
	Context context;
	AlertDialog ad;

	public AlertDialog getAd() {
		return ad;
	}

	TextView messageView;
	Window window;

	public CustomAlertDialog(Context context) {
		this.context = context;
		ad = new AlertDialog.Builder(context, R.style.MyDialog).create();
		ad.setCancelable(false);
		ad.show();
		// 关键在下面的两行,使用window.setContentView,替换整个对话框窗口的布局
		window = ad.getWindow();
		window.setContentView(R.layout.custom_alert_dialog);
		messageView = (TextView) window.findViewById(R.id.message);
	}

	public void setMessage(int resId) {
		messageView.setText(resId);
	}

	public void setMessage(String message) {
		messageView.setText(message);
	}

	/**
	 * 设置按钮
	 * 
	 * @param text
	 * @param listener
	 */
	public void setNegativeButton(int id, String text, final View.OnClickListener listener, int visibility) {
		TextView button =  window.findViewById(id);
		button.setText(text);
		button.setOnClickListener(listener);
		button.setVisibility(visibility);

	}

	public void setNegativeButtonHidden(int id) {
		TextView button =  window.findViewById(id);
		button.setVisibility(View.GONE);

	}

	public void setViewHidden(int id, int visibility) {
		View view = window.findViewById(id);
		view.setVisibility(visibility);
	}

	public void dismiss() {
		ad.dismiss();
	}

}
